<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/base/taglibs.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>${systemOption.systemTitle}</title>
    <%@ include file="/base/head.jsp"%>
    <script type="text/javascript" charset="UTF-8">
    
        	//增加
  	function add_station(){
  		$('#stationAddWnd').show();
            $('#stationAddWnd').dialog({
            	iconCls:'icon-user-add',
            	title:'增加岗位',
            	modal:true,
            	buttons: [{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					$('#stationAddForm').form('submit',{  
					    success: function(data){   
					        if(data=='true'){  
					            $.messager.alert('友情提示','增加成功','info'); 
					            resetDG('#station'); 
					        }else{
					        	$.messager.alert('友情提示','增加失败','error'); 
					        } 
					        $('#stationAddWnd').dialog('close');
					    }  
					});
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#stationAddWnd').dialog('close');
				}
		}]
            });                
  		$('#stationAddForm').form('reset');
  		$('#firstBox').focus();  
  	}
  //修改
  function edit_station(){
  	var row = $('#station').datagrid('getSelected');
	if (!row){
		$.messager.alert('友情提示','请选择用户','error');
	}else{
		if(row.stationCode=='000'){
			$.messager.alert('友情提示','管理员岗位不可修改','error');
			return;
		}
		$('#stationUpdateWnd').show();
		$('#stationUpdateWnd').dialog({
        iconCls:'icon-user-edit',
        title:'修改岗位',
        modal:true,
        buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					$('#stationUpdateForm').form('submit',{
					    success: function(data){
					        if(data=='true'){
					            $.messager.alert('友情提示','修改成功','info');
					            resetDG('#station');
					        }else{
					        	$.messager.alert('友情提示','修改失败','error');
					        }
					        $('#stationUpdateWnd').dialog('close');
					    }
					});
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#stationUpdateWnd').dialog('close');
				}
		}]
            });
            //加载数据
            $.post("${ctx}/json/loadStation.action", {"id": row.id },
			   function(data){
			    if(data){
			        $('#stationId').val(data.id);
			        $('#ssgsid').val(data.ssgsid);
					$('#stationStationCode').textbox('setValue',data.stationCode);
					$('#stationStationName').textbox('setValue',data.stationName);
					$('#stationStationRemark').textbox('setValue',data.stationRemark);
					$('#stationStationCode').textbox({
						validType : 'remote["${ctx}/json/checkStationCode.action?id='+data.id+'","stationCodeChk"]',
						invalidMessage : '岗位代码重复!'
					});
				}else{
					$.messager.alert('友情提示','加载失败','error');
				}
			   }, "json");


	}
	}
	function remove_station(){
    		var row = $('#station').datagrid('getSelected');
			if (!row){
				$.messager.alert('友情提示','请选择岗位','error');
			}else{
				if(row.stationCode=='000'){
					$.messager.alert('友情提示','管理员岗位不可删除','error');
					return;
				}
				$.messager.confirm('友情提示','将删除该岗位，确定么？',function(r){   
				    if (r){   
				       $.post("${ctx}/json/removeStation.action", {"id": row.id },
					   function(data){
					    if(data=="1"){  
							$.messager.alert('友情提示','删除成功','info'); 
							resetDG('#station');
						}else if(data=="2"){
							$.messager.alert('友情提示','请先删除所在岗位下的人员','error'); 
						}else{
							$.messager.alert('友情提示','删除失败','error'); 
						}
					   }, "json");   
				    }   
				});
			
			}
    	}
  //分页查询
  function doQuery(){
  	var queryParams=$('#station').datagrid('options').queryParams;
  	queryParams.stationCode=$('#stationCode').val();
  	queryParams.stationName=$('#stationName').val();
  	//queryParams.stationRemark=$('#stationRemark').val();
  	
  	//重置当前页数为1
  	resetDG('#station');

  } 
  
  $(function(){
  /* 	$('#stationCode').bind('input propertychange', function() {
   		doQuery();
	}); */
  });
    
    </script>  
        
  </head>
  
  <body>
 
<!-- 主窗口 -->  	 
    <table id="station" class="easyui-datagrid" data-options="fit:true,
    								rownumbers:true,
									singleSelect:true,
									striped:true,
									fitColumns:true,
									toolbar:'#tb',
									pagination:true,
									pageSize:20,
									pageList:[20,30,50,100],
									url:'${ctx}/json/listStation.action'">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'stationCode',align:'center'" width="200"><strong>岗位编码</strong></th>
				<th data-options="field:'stationName',align:'center'" width="200"><strong>岗位名称</strong></th>
				<th data-options="field:'stationRemark',align:'center'" width="300"><strong>备注</strong></th>
				<th data-options="field:'id',hidden:true"></th>
			</tr>
		</thead>
		
	</table>
<!-- Datagrid工具栏 -->
<div id="tb">
	<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
	   <td class="toolDiv">  		
	  		<a href="javascript:void(0)" onclick="add_station()" class="easyui-linkbutton" data-options="iconCls:'icon-user-add',plain:true">增加岗位</a><span class="vline">|</span>
			<a href="javascript:void(0)" onclick="edit_station()" class="easyui-linkbutton" data-options="iconCls:'icon-user-edit',plain:true">修改岗位</a><span class="vline">|</span>
			<a href="javascript:void(0)" onclick="remove_station()" class="easyui-linkbutton" data-options="iconCls:'icon-user-delete',plain:true">刪除岗位</a><span class="vline">|</span>
		</td>
	</tr>
	<tr>
	   <td class="serchDiv">
			岗位编码：<input id="stationCode" oninput="doQuery()" onpropertychange="doQuery()" onchange="doQuery()" class="easyui-textbox" type="text">
			&nbsp;&nbsp;岗位名称：<input id="stationName" oninput="doQuery()" onpropertychange="doQuery()"  class="easyui-textbox" type="text">
			<!--  &nbsp;&nbsp;岗位备注：<input id="stationRemark" class="easyui-validatebox" type="text">-->
			&nbsp;&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" 
			onclick="doQuery()">查询</a>
		</td>
	</tr>
	</table>
</div>
<!--增加窗口-->
    <div id="stationAddWnd"  style="width: 310px; height: 220px; padding: 5px; background: #fafafa;display: none">
    	<form id="stationAddForm" method="post" action="${ctx }/json/saveStation.action">
                <table cellpadding=3>
                	<tr>
                        <td>岗位编码：</td>
                        <td><input id="firstBox" name="stationCode" class="easyui-textbox"  data-options="required:true" validType="remote['${ctx}/json/checkStationCode.action','stationCodeChk']" invalidMessage="岗位代码重复!" style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>岗位名称：</td>
                        <td><input name="stationName" class="easyui-textbox"  data-options="required:true" style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>岗位备注：</td>
                        <td>
                        	<input name="stationRemark" class="easyui-textbox" data-options="multiline:true" style="width:200px;;height:50px">
	                    </td>
					</tr>
                </table>
        </form>
    </div>
<!--修改窗口-->
    <div id="stationUpdateWnd"  style="width: 310px; height: 220px; padding: 5px; background: #fafafa;display: none">
    	<form id="stationUpdateForm" method="post" action="${ctx }/json/saveStation.action">
    			<input id="stationId" name="id" type="hidden"/>
    			<input id="ssgsid" name="ssgsid" type="hidden"/>
                <table cellpadding=3>
                	<tr>
                        <td>岗位编码：</td>
                        <td><input id="stationStationCode" name="stationCode" class="easyui-textbox"  data-options="required:true" style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>岗位名称：</td>
                        <td><input id="stationStationName" name="stationName" class="easyui-textbox"  data-options="required:true" style="width:200px"/></td>
                    </tr>
					  <tr>
                        <td>岗位备注：</td>
                        <td>
                        	<input id="stationStationRemark" name="stationRemark" class="easyui-textbox" data-options="multiline:true" style="width:200px;;height:50px">
	                    </td>
					</tr>
                </table>
        </form>
    </div> 

  </body>
</html>
